//----------------------------------------------------------------
//Tên Class: Cls_LoaiHinhDoanhNghiep
//Người thực hiện: NhatTHM
//Website: www.nhatthanh.net
//-----------------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace Library.Business {
	public partial class Cls_LoaiHinhDoanhNghiep
	{
		protected string sSQL;
		//Tham số cho Procudure
		#region Tham số cho Procudure
		protected const string st_LoaiHinhDoanhNghiep_Insert = "st_LoaiHinhDoanhNghiep_Insert";
		protected const string st_LoaiHinhDoanhNghiep_Update = "st_LoaiHinhDoanhNghiep_Update";
		protected const string st_LoaiHinhDoanhNghiep_Update_ALL = "st_LoaiHinhDoanhNghiep_Update_ALL";
		protected const string st_LoaiHinhDoanhNghiep_Update_Hidden = "st_LoaiHinhDoanhNghiep_Update_Hidden";
		protected const string st_LoaiHinhDoanhNghiep_Delete = "st_LoaiHinhDoanhNghiep_Delete";
		protected const string st_LoaiHinhDoanhNghiep_SelectAll = "st_LoaiHinhDoanhNghiep_SelectAll";
		protected const string st_LoaiHinhDoanhNghiep_SelectAll_Key = "st_LoaiHinhDoanhNghiep_SelectAll_Key";
		protected const string st_LoaiHinhDoanhNghiep_SelectByID = "st_LoaiHinhDoanhNghiep_SelectByID";
		protected const string st_LoaiHinhDoanhNghiep_SelectByID_Stand = "st_LoaiHinhDoanhNghiep_SelectByID_Stand";
		protected const string TABLE_NAME = "tbLoaiHinhDoanhNghiep";
		#endregion Tham số cho Procudure
		//Các tên filed của table.
		#region Các tên filed của table.
		public const string fn_STT = "STT";
		public const int len_STT = 4;
		public const string fn_ID_LoaiHinhDoanhNghiep = "ID_LoaiHinhDoanhNghiep";
		public const int len_ID_LoaiHinhDoanhNghiep = 30;
		public const string fn_Ten_LoaiHinhDoanhNghiep = "Ten_LoaiHinhDoanhNghiep";
		public const int len_Ten_LoaiHinhDoanhNghiep = 100;
		public const string fn_Hidden = "Hidden";
		public const int len_Hidden = 1;
		//Các filed của table.
		private int _sTT;
		private string _iD_LoaiHinhDoanhNghiep_find;
		private string _iD_LoaiHinhDoanhNghiep;
		private string _ten_LoaiHinhDoanhNghiep;
		private bool _hidden;
		#endregion Các tên filed của table.
		#region Các phương thức cho table.
		//Thuộc tính STT
		public int STT
		{
			get{return this._sTT;}
			set{this._sTT = value;}
		}
		//Thuộc tính ID_LoaiHinhDoanhNghiep_find
		public string ID_LoaiHinhDoanhNghiep_find
		{
			get{return this._iD_LoaiHinhDoanhNghiep_find;}
			set{this._iD_LoaiHinhDoanhNghiep_find = value;}
		}
		//Thuộc tính ID_LoaiHinhDoanhNghiep
		public string ID_LoaiHinhDoanhNghiep
		{
			get{return this._iD_LoaiHinhDoanhNghiep;}
			set{this._iD_LoaiHinhDoanhNghiep = value;}
		}
		//Thuộc tính Ten_LoaiHinhDoanhNghiep
		public string Ten_LoaiHinhDoanhNghiep
		{
			get{return this._ten_LoaiHinhDoanhNghiep;}
			set{this._ten_LoaiHinhDoanhNghiep = value;}
		}
		//Thuộc tính Hidden
		public bool Hidden
		{
			get{return this._hidden;}
			set{this._hidden = value;}
		}
		#endregion Các phương thức cho table.
		/// <summary>
		/// Hàm khởi tạo không có tham số.
		/// </summary>
		public Cls_LoaiHinhDoanhNghiep()
		{
		}

		/// <summary>
		/// Hàm khởi tạo có  tham số.
		/// </summary>
		public Cls_LoaiHinhDoanhNghiep(int stt, string id_loaihinhdoanhnghiep, string ten_loaihinhdoanhnghiep, bool hidden)
		{
			this._sTT = stt;
			this._iD_LoaiHinhDoanhNghiep = id_loaihinhdoanhnghiep;
			this._ten_LoaiHinhDoanhNghiep = ten_loaihinhdoanhnghiep;
			this._hidden = hidden;
		}
        /// <summary>
        /// Đếm tổng số bảng ghi.
        /// </summary>
        /// <returns></returns>
        public static int countRows(bool Hidden)
        {
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_LoaiHinhDoanhNghiep_Count", con);
            sqlComm.CommandType = CommandType.StoredProcedure;
            sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
            try
            {
                con.Open();
                int intResult= (int)sqlComm.ExecuteScalar();
                return intResult;
            }
            catch (SqlException ex)
            {
                new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
                throw ex;
            }
            finally
            {
                if (sqlComm != null) sqlComm.Dispose();
                if (con != null) con.Close();
            }
        }
        /// <summary>
        /// Xác định Khóa chính có tồn tại dữ liệu.
        /// </summary>
        /// <returns>Truy: Có; False: Không</returns>
        public bool Exits_Key()
        {
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_LoaiHinhDoanhNghiep_Count_Key", con);
            sqlComm.CommandType = CommandType.StoredProcedure;
            try
            {
                sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep;
                con.Open();
                if (((int)sqlComm.ExecuteScalar()) == 1) return true;
                else return false;
            }
            catch (SqlException ex)
            {
                new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
                throw ex;
                return false;
            }
            finally
            {
                if (sqlComm != null) sqlComm.Dispose();
                if (con != null) con.Close();
            }
        }
        /// <summary>
        /// Xác định Khóa chính có tồn tại dữ liệu.
        /// </summary>
        /// <returns>Truy: Có; False: Không</returns>
        public static bool Exits_Key(string key_ID_LoaiHinhDoanhNghiep)
        {
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_LoaiHinhDoanhNghiep_Count_Key", con);
            sqlComm.CommandType = CommandType.StoredProcedure;
            try
            {
                sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = key_ID_LoaiHinhDoanhNghiep;
                con.Open();
                if (((int)sqlComm.ExecuteScalar()) == 1) return true;
                else return false;
            }
            catch (SqlException ex)
            {
                new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
                throw ex;
                return false;
            }
            finally
            {
                if (sqlComm != null) sqlComm.Dispose();
                if (con != null) con.Close();
            }
        }
		/// <summary>
		/// Get DataTable NULL với table class.
		/// </summary>
		/// <returns></returns>
		public static DataTable getDataTable_NULL()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand("Select Top 0 * From tbLoaiHinhDoanhNghiep", con);
			sqlComm.CommandType = CommandType.Text;
			try
			{
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataTable dt = new DataTable();
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <returns></returns>
		public static DataTable getDataTable_My_Key()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_SelectAll_Key, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataTable dt = new DataTable();
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với Where time.
		/// </summary>
		/// <param name="strWhere">Where get ucChonNgay t</param>
		/// <returns></returns>
		public static DataTable getDataTable_Time(string strWhere)
		{
			try
			{
				string sSQL = "SELECT * FROM tbLoaiHinhDoanhNghiep" + strWhere;
				return getDataTable_SQL_pro(sSQL);
			}
			catch (SqlException ex)
			{
				return null;
			}
		}

		/// <summary>
		/// Get DataTable với Where.
		/// </summary>
		/// <returns></returns>
		public static DataTable getDataTable_Where(string strWhere,string FieldSort)
		{
			try
			{
			    if (FieldSort.Trim().Length == 0) FieldSort = "";
			    else FieldSort = " Order By " + FieldSort;
			    //
			    if (strWhere.Trim().Length == 0) strWhere = "";
			    else strWhere = " WHERE " + strWhere;
				string sSQL = "SELECT * FROM tbLoaiHinhDoanhNghiep" + strWhere + FieldSort ;
				return getDataTable_SQL_pro(sSQL);
			}
			catch (SqlException ex)
			{
				return null;
			}
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataTable getDataTable_SQL_pro(string sSQL)
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand("st_processSQL",con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			DataTable dt = new DataTable();
			try
			{
				sqlComm.Parameters.Add("@sSQL", SqlDbType.NVarChar).Value = sSQL;
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, sSQL + " - " + ex.Message);
		        throw ex;
			}
            finally
            {
                if (dt != null) dt.Dispose();
                if (sqlComm != null) sqlComm.Dispose();
                if (con != null) con.Close();
            }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataTable getDataTable_My()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_SelectAll, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		    DataTable dt = new DataTable();
			try
			{
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (dt != null) dt.Dispose();
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataSet getDataSet_My()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_SelectAll, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		    DataSet ds = new DataSet();
			try
			{
		        con.Open();
				sqlDTA.Fill(ds);
				return ds;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (ds != null) ds.Dispose();
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		public static DataTable getDataTable_Hidden(bool Hidden)
		{
		    SqlConnection con = new AccessDB().get_Conn();
		    SqlCommand sqlComm = new SqlCommand("st_LoaiHinhDoanhNghiep_SelectAll_Hidden", con);
		    sqlComm.CommandType = CommandType.StoredProcedure;
		    sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;

		    SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		    DataTable dt = new DataTable();
			try
			{
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
				return null;
			}
		    finally
		    {
		        if (sqlDTA != null) sqlDTA.Dispose();
		        if (dt != null) dt.Dispose();
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		public static DataSet getDataSet_Hidden(bool Hidden)
		{
		    SqlConnection con = new AccessDB().get_Conn();
		    SqlCommand sqlComm = new SqlCommand("st_LoaiHinhDoanhNghiep_SelectAll_Hidden", con);
		    sqlComm.CommandType = CommandType.StoredProcedure;
		    sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;

		    SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		    DataSet ds = new DataSet();
			try
			{
		        con.Open();
				sqlDTA.Fill(ds);
				return ds;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlDTA != null) sqlDTA.Dispose();
		        if (ds != null) ds.Dispose();
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataTable getDataTable_My(string key_ID_LoaiHinhDoanhNghiep)
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_SelectByID, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
		        con.Open();
				//
				sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = key_ID_LoaiHinhDoanhNghiep;
				//
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataTable dt = new DataTable();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataSet getDataSet_My(string key_ID_LoaiHinhDoanhNghiep)
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_SelectByID, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
		        con.Open();
				//
				sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = key_ID_LoaiHinhDoanhNghiep;
				//
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataSet ds = new DataSet();
				sqlDTA.Fill(ds);
				return ds;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Lấy giá trị Max của column table tbLoaiHinhDoanhNghiep
		/// </summary>
		public static int getMaxSTT()
		{
			    string sSQL = "SELECT Max(STT) FROM tbLoaiHinhDoanhNghiep";
		    SqlConnection con = new AccessDB().get_Conn();
		    SqlCommand sqlComm = new SqlCommand(sSQL,con);
		    try
		    {
		        con.Open();
		        sqlComm.CommandType = CommandType.Text;
		        string strResult=sqlComm.ExecuteScalar().ToString();
		        if (strResult == "")
		            return 0;
		        else
		            return int.Parse(strResult);
		    }

		    catch (SqlException ex)
		    {

		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
		    }
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}
        /// <summary>
        /// Get value ID by column STT.
        /// </summary>
        /// <param name="STT"></param>
        /// <returns></returns>
        public static string getIdBySTT(int STT)
        {
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_LoaiHinhDoanhNghiep_getIDbySTT",con);
            try
            {
                con.Open();
                sqlComm.CommandType = CommandType.StoredProcedure;
                sqlComm.Parameters.Add("@STT", SqlDbType.Int).Value = STT;
                string strResult=sqlComm.ExecuteScalar().ToString();
                if (strResult == "")
                    return "";
                else
                    return strResult;
            }

            catch (SqlException ex)
            {
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
                return "";
            }
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
        }
		/// <summary>
		/// Thực hiện SQL dữ liệu.
		/// </summary>
		/// <returns></returns>
		public static bool doSQL(string sSQL)
		{
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_processSQL", con);
            sqlComm.CommandType = CommandType.StoredProcedure;
            sqlComm.Parameters.Add("@sSQL", SqlDbType.NVarChar).Value = sSQL;
			try
			{
                con.Open();
				sqlComm.ExecuteNonQuery();
				return true;
			}
			catch (SqlException  ex)
			{
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện Insert dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doInsert()
		{
        SqlConnection con = new AccessDB().get_Conn();
		SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_Insert,con);
        sqlComm.CommandType = CommandType.StoredProcedure;
        try
        {
				//
			    sqlComm.Parameters.Add("@STT", SqlDbType.Int).Value = STT;
				//ID_LoaiHinhDoanhNghiep
				if(ID_LoaiHinhDoanhNghiep!=null)
				    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep;
				else
				    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = DBNull.Value;
				//Ten_LoaiHinhDoanhNghiep
				if(Ten_LoaiHinhDoanhNghiep!=null)
				    sqlComm.Parameters.Add("@Ten_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = Ten_LoaiHinhDoanhNghiep;
				else
				    sqlComm.Parameters.Add("@Ten_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = DBNull.Value;
			    sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
                con.Open();
				sqlComm.ExecuteNonQuery();
				return 1;
			}
			catch (SqlException  ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện update dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doUpdate()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_Update,con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
		        con.Open();
			    sqlComm.Parameters.Add("@STT", SqlDbType.Int).Value = STT;
				//ID_LoaiHinhDoanhNghiep_find
				sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep_find", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep_find;
				//ID_LoaiHinhDoanhNghiep
				if(ID_LoaiHinhDoanhNghiep!=null)
				    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep;
				else
				    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = DBNull.Value;
				//Ten_LoaiHinhDoanhNghiep
				if(Ten_LoaiHinhDoanhNghiep!=null)
				    sqlComm.Parameters.Add("@Ten_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = Ten_LoaiHinhDoanhNghiep;
				else
				    sqlComm.Parameters.Add("@Ten_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = DBNull.Value;
				int up= sqlComm.ExecuteNonQuery();
				ID_LoaiHinhDoanhNghiep=ID_LoaiHinhDoanhNghiep_find;
				return up;
			}
			catch (SqlException  ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện update dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doUpdate_ALL()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_Update_ALL,con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
		        con.Open();
				//STT
				sqlComm.Parameters.Add("@STT", SqlDbType.Int).Value = STT;
				//ID_LoaiHinhDoanhNghiep_find
				sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep_find", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep_find;
				//ID_LoaiHinhDoanhNghiep
				sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep;
				//Ten_LoaiHinhDoanhNghiep
				sqlComm.Parameters.Add("@Ten_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = Ten_LoaiHinhDoanhNghiep;
				//Hidden
				sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
				int up = sqlComm.ExecuteNonQuery();
				ID_LoaiHinhDoanhNghiep=ID_LoaiHinhDoanhNghiep_find;
				return up;
			}
			catch (SqlException  ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện update dữ liệu.
		/// </summary>
		/// <returns></returns>
		public static int doUpdate_KEY(string Key_ID_LoaiHinhDoanhNghiep_Old,string Key_ID_LoaiHinhDoanhNghiep_New)
		{
		    SqlConnection con = new AccessDB().get_Conn();
		    string sql = "Update tbLoaiHinhDoanhNghiep Set ID_LoaiHinhDoanhNghiep=@ID_LoaiHinhDoanhNghiep_New Where ID_LoaiHinhDoanhNghiep=@ID_LoaiHinhDoanhNghiep_old";
			SqlCommand sqlComm = new SqlCommand(sql,con);
			sqlComm.CommandType = CommandType.Text;
			try
			{
			    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep_New", SqlDbType.NVarChar).Value = Key_ID_LoaiHinhDoanhNghiep_New;
			    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep_old", SqlDbType.NVarChar).Value = Key_ID_LoaiHinhDoanhNghiep_Old;
		        con.Open();
		        sqlComm.ExecuteNonQuery();
		        return 1;
		    }
		    catch (SqlException  ex)
		    {
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
		    }
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện update dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doUpdateHidden()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_Update_Hidden, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
				//ID_LoaiHinhDoanhNghiep
				sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep_find;
				sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
		        con.Open();
				sqlComm.ExecuteNonQuery();
				return 1;
			}
			catch (SqlException  ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				return -1;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		///  Thực hiện update dữ liệu với table là kiểu List.
		/// </summary>
		/// <returns></returns>
		public int doUpdateList()
		{
		        SqlConnection con = new AccessDB().get_Conn();
		    SqlCommand sqlComm = new SqlCommand("st_LoaiHinhDoanhNghiep_Update_List", con);
		    sqlComm.CommandType = CommandType.StoredProcedure;
		    try
		    {
		        //
		        //STT
		        sqlComm.Parameters.Add("@STT", SqlDbType.Int).Value = STT;
		        //ID_LoaiHinhDoanhNghiep_find
		        sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep_find", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep_find;
		        con.Open();
		        sqlComm.ExecuteNonQuery();
		        return 1;
		    }
		    catch (SqlException ex)
		    {
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        return -1;
		    }
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện xóa dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doDelete()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_LoaiHinhDoanhNghiep_Delete, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
				sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep_find ;
				//
		        con.Open();
		    	sqlComm.ExecuteNonQuery() ;
				return 1;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Conver sang Object.
		/// </summary>
		/// <returns></returns>
		public static Cls_LoaiHinhDoanhNghiep converDataRow_To_Object(DataRow dr)
		{
			Cls_LoaiHinhDoanhNghiep _Object = new Cls_LoaiHinhDoanhNghiep();
		    if( dr[fn_STT]!= DBNull.Value )
		        _Object.STT =  (int)dr[fn_STT];
		    if( dr[fn_ID_LoaiHinhDoanhNghiep]!= DBNull.Value )
		        _Object.ID_LoaiHinhDoanhNghiep =  (string)dr[fn_ID_LoaiHinhDoanhNghiep];
		    if( dr[fn_Ten_LoaiHinhDoanhNghiep]!= DBNull.Value )
		        _Object.Ten_LoaiHinhDoanhNghiep =  (string)dr[fn_Ten_LoaiHinhDoanhNghiep];
		    if( dr[fn_Hidden]!= DBNull.Value )
		        _Object.Hidden =  (bool)dr[fn_Hidden];
		    //============
		    return _Object;
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static Cls_LoaiHinhDoanhNghiep getOject_Key(string key_ID_LoaiHinhDoanhNghiep)
		{
		    DataTable dt = getDataTable_My(key_ID_LoaiHinhDoanhNghiep);
		    //==========================
		    if (dt.Rows.Count > 0)
		        return converDataRow_To_Object(dt.Rows[0]);
		    else
		        return null;
		}

		/// <summary>
		/// Get Array object class.
		/// </summary>
		/// <returns></returns>
		public static Cls_LoaiHinhDoanhNghiep[] getArrayObject(DataTable dt)
		{
		    if (dt.Rows.Count == 0) return null;
		    //
		    Cls_LoaiHinhDoanhNghiep[] arr = new Cls_LoaiHinhDoanhNghiep[dt.Rows.Count];
		    int i = 0;
		    foreach (DataRow dr in dt.Rows)
		    {
		    
		        arr[i] = converDataRow_To_Object( dr  );
		        i++;
		    }
		    return arr;
		}

		/// <summary>
		/// Get Array object class.
		/// </summary>
		/// <returns></returns>
		public static Cls_LoaiHinhDoanhNghiep[] getArrayObject()
		{
		    return getArrayObject( getDataTable_My() );
		}

	}

}
